<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    .container {
        margin-top: 50px;
    }

    .form-control{
        margin-top: 10px;
    }
    button{
        margin-top: 10px;
    }
    .kuai{
        width: 1150px;
        height: 150px;
        background-color: #eeeeee;
    }
</style>

<body>
        <div id="app" class="container" @keyup.9="gettab">
                <button  class="btn" :class="tag?'btn-defauit':'btn-primary'">评论管理</button>
                <button  class="btn" :class="tag?'btn-primary':'btn-defauit'">发布评论</button>

            <div class="table" v-show="tag">
                <input type="text" placeholder="昵称" class="form-control" v-model="userInfo.username">
                <input type="text" placeholder="评论内容" class="form-control" v-model="userInfo.content">
                <button @click="addUser">立即提交</button>
            </div>

            <div v-for="(item,index) in persons" :key="item.id" class="kuai" v-show="!tag">
                <p>{{item.username}}</p>
                <p>{{item.content}}</p>
                <p>{{item.addTime}}</p> 
            </div>
        </div>

    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <script>
        new Vue({
            el: '#app',
            data: {
                tag:true,
                index: 1,
                id: '',
                persons: [
                ],
                userInfo: {
                    username: '',
                    content: ''
                }
            },
            methods: {
                //添加功能
                addUser() {
                    let user = {
                        id: Math.random(),
                        addTime: new Date().toLocaleDateString(), //按理说应该自己格式化
                        ...this.userInfo,//... 把userInfo上的数据拷贝到user变量上
                    }
                    this.userInfo = {}
                    //追加到数组的末尾，从而影响视图的变化
                    this.persons.push(user)
                },

                gettab(ev){
                    
                    this.tag = !this.tag
                    console.log(this.tag);
                }
            

            },
        })
    </script>
</body>

</html>